package com.yxuan.springboot.util;

/**
  * @className: VerificationCodeUtil.java
  * @methodName: VerificationCodeUtil
  * @effect: 生成验证码的工具类
  * @author: JingxuanFan
  * @date: 2023/3/27 21:11
  **/
public class VerificationCodeUtil {

    /**
     * @methodName generateCheckCode
     * @effect: 生成数字验证码
     */
    public static String generateCheckCode1(int num) {
        String chars = "0123456789";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * 10 ); //数字
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

    /**
     * @methodName generateCheckCode2
     * @effect: 生成小写字母验证码
     */
    public static String generateCheckCode2(int num) {
        String chars = "abcdefghijklmnopqrstuvwxyz";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * 26 );
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

    /**
     * @methodName generateCheckCode3
     * @effect: 生成大写字母验证码
     */
    public static String generateCheckCode3(int num) {
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * 26 );
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

    /**
     * @methodName generateCheckCode4
     * @effect: 生成数字+小写字母的随机验证码
     */
    public static String generateCheckCode4(int num) {
        String chars = "0123456789"+ "abcdefghijklmnopqrstuvwxyz";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * (26 + 10));
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

    /**
     * @methodName generateCheckCode5
     * @effect: 生成数字+大写字母的随机验证码
     */
    public static String generateCheckCode5(int num) {
        String chars = "0123456789"+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * (26 + 10));
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

    /**
     * @methodName generateCheckCode6
     * @effect: 生成小写字母+大写字母的随机验证码
     */
    public static String generateCheckCode6(int num) {
        String chars = "abcdefghijklmnopqrstuvwxyz"+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * (26 * 2));
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }


    /**
     * @methodName generateCheckCode7
     * @effect: 生成数字+小写字母+大写字母的随机验证码
     */
    public static String generateCheckCode7(int num) {
        String chars = "0123456789"+ "abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * (26 * 2 + 10));
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }
    /*
    * 生成数字+小写字母+大写字母的随机验证码,去除了0,o,i,l,O,I,L,目的是防止用户输错
    * */
    public static String generateCheckCode8(int num) {
        String chars = "123456789"+ "abcdefghjkmnpqrstuvwxyz" +"ABCDEFGHJKMNPQRSTUVWXYZ";
        String rands = "";
        for (int i = 0; i < num; i++) {
            int rand = (int) (Math.random() * (26 * 2 + 10));
            rands = rands + (chars.charAt(rand));
        }
        return rands;
    }

}
